import axios from '@/utils/request'

/**
 * 获取查询文章列表
 * @param {*} param0
 * @returns
 */
export const getSearchArticleListAPI = ({ artId, page = 1, per_page = 10 }) => axios({
  url: '/v1_0/search',
  params: {
    q: artId,
    page: page,
    per_page: per_page
  }
})
/**
   * 获取文章详情
   * @param {*} artId
   * @returns
   */
export const getArticleDetailAPI = (artId) => axios({
  url: '/v1_0/articles/' + artId
})

/**
   * 关注作者
   * @param {*} autId
   * @returns
   */
export const followedAuthorAPI = (autId) => axios({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: {
    target: autId
  }

})

/**
   * 取消关注作者
   * @param {*} autId
   * @returns
   */
export const unFollowedAuthorAPI = (autId) => axios({
  url: '/v1_0/user/followings/' + autId,
  method: 'DELETE'
})

/**
   * 点赞文章
   * @param {*} artId
   * @returns
   */
export const likeArticleAPI = (artId) => axios({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target: artId
  }
})

/**
   * 取消对文章点赞
   * @param {*} artId
   * @returns
   */
export const unLikeArticleAPI = (artId) => axios({
  url: '/v1_0/article/likings/' + artId,
  method: 'DELETE'
})

/**
   * 获取评论列表
   * @param {*} param0
   * @returns
   */
export const getCommentListAPI = ({ artId, offset = null, limit = 10 }) => axios({
  url: '/v1_0/comments',
  params: {
    type: 'a',
    source: artId,
    offset: offset,
    limit: limit
  }
})

/**
   * 喜欢评论
   * @param {*} commentId
   * @returns
   */
export const likeCommentAPI = (commentId) => axios({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: {
    target: commentId
  }
})

/**
   * 不 喜欢评论
   * @param {*} commentId
   * @returns
   */
export const unLikeCommentAPI = (commentId) => axios({
  url: '/v1_0/comment/likings/' + commentId,
  method: 'DELETE'

})

/**
   * 发布评论
   * @param {*} param0
   * @returns
   */
export const publishCommentAPI = ({ target, content, artId }) => axios({
  url: '/v1_0/comments',
  method: 'POST',
  data: {
    target: target,
    content: content,
    art_id: artId
  }
})
/**
 * 文章列表
 * @param {}
 * @returns Promise对象
 */
export const getArticleListAPI = ({ channel_id, timestamp }) => axios({
  url: '/v1_0/articles',
  params: {
    channel_id,
    timestamp
  }
})

/**
   * 用户不感兴趣的文章
   * @param {*} artId
   * @returns
   */
export const dislikeArticleAPI = (artId) => axios({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  data: {
    target: artId
  }
})

/**
   * 用户举报的文章
   * @param {*} param0
   * @returns
   */
export const reportArticleAPI = ({ artId, type }) => axios({
  url: '/v1_0/article/reports',
  method: 'POST',
  data: {
    target: artId,
    type: type,
    remark: '其他问题，标记成功'
  }
})

/**
 * 关键字查询提示
 * @param {*} keyword
 * @returns
 */
export const searchSuggestion = (keyword) => axios({
  url: '/v1_0/suggestion',
  params: {
    q: keyword
  }
})
